package com.zup.algorithm.util;

import java.util.Arrays;
import java.util.Random;

/**
 * 说明：
 *
 * @author Created by xujinyan on 2018/5/14.
 */
public class SortUtils {
    /**
     * 交换数组元素
     */
    public static void swap(int[] arr, int m, int n) {
        int temp = arr[m];
        arr[m] = arr[n];
        arr[n] = temp;
    }

    /**
     * 检验是否排好序
     */
    public static void checkIsSorted(int[] arr) {
        for (int i = 0; i < arr.length-1; i++) {
            if (arr[i] > arr[i + 1]) {
                System.out.println("sort is failure");
                return;
            }
        }
        System.out.println("sort is success");
    }

    /**
     * 生成一个待排序数组
     */
    public static int[] generateArr(int n, int randomSeed) {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            Random random = new Random();
            arr[i] = random.nextInt(randomSeed);
        }
        System.out.println("generate arr:" + Arrays.toString(arr));
        return arr;
    }
}
